<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
      .box {
        width: 800px;
        height: 800px;
      }
      .red {
        background-color: red;
      }
      .green {
        background-color: green;
      }
      .border {
        border: 1px solid #000;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 动态class绑定写法一:字符串拼接 (类只有一个)-->
      <div class="box" :class="isRed?'red':'green'"></div>

      <!-- 动态class绑定写法二:对象写法 (类有多个固定个数,都写在对象的key上,值为布尔值,控制布尔值控制类)-->
      <div class="box" :class="{border:true,red:true,green:false}"></div>
      <div class="box" :class="{border:true,red:isRed?'true':'false',green:false}"></div>
      <div class="box" :class="boxClass"></div>

      <!-- 动态class绑定写法三:数组写法 (类有多个不固定个数,但是不确定有哪些,把类都放在数组中即可)-->
      <div class="box" :class="boxClass"></div>
    </div>

    <script>
      Vue.config.productionTip = false;

      const vm = new Vue({
        el: "#app",
        data() {
          return {
            isRed: true,
            boxClass: { border: true, red: true, green: false },
            boxArrClass: ["red", "border", "box"],
          };
        },
      });
    </script>
  </body>
</html>
